package com.ruoyi.web.controller.market.source;

import java.util.List;
import java.util.Map;

import com.ruoyi.db.domain.SourceDataCountInfo;
import com.ruoyi.web.wapper.SourceDataCountInfoWapper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.source.service.ISourceDataCountInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 线索数据统计Controller
 * 
 * @author ruoyi
 * @date 2024-08-27
 */
@Controller
@RequestMapping("/source/dataCountInfo")
public class SourceDataCountInfoController extends BaseController
{
    private String prefix = "source/dataCountInfo";

    @Autowired
    private ISourceDataCountInfoService sourceDataCountInfoService;

    @RequiresPermissions("source:dataCountInfo:view")
    @GetMapping()
    public String dataCountInfo()
    {
        return prefix + "/dataCountInfo";
    }

    /**
     * 查询线索数据统计列表
     */
    @RequiresPermissions("source:dataCountInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SourceDataCountInfo sourceDataCountInfo)
    {

        Map<String, Object> totalMap = sourceDataCountInfoService.selectSourceDataCountInfoTotalMap(sourceDataCountInfo);

        startPage();
        List<Map<String, Object>> mapList = sourceDataCountInfoService.selectSourceDataCountInfoListMap(sourceDataCountInfo);

        mapList.add(0, totalMap);

        mapList = new SourceDataCountInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出线索数据统计列表
     */
    @RequiresPermissions("source:dataCountInfo:export")
    @Log(title = "线索数据统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SourceDataCountInfo sourceDataCountInfo)
    {
        List<SourceDataCountInfo> list = sourceDataCountInfoService.selectSourceDataCountInfoList(sourceDataCountInfo);
        ExcelUtil<SourceDataCountInfo> util = new ExcelUtil<SourceDataCountInfo>(SourceDataCountInfo.class);
        return util.exportExcel(list, "线索数据统计数据");
    }

    /**
     * 新增线索数据统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存线索数据统计
     */
    @RequiresPermissions("source:dataCountInfo:add")
    @Log(title = "线索数据统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SourceDataCountInfo sourceDataCountInfo)
    {
        return toAjax(sourceDataCountInfoService.insertSourceDataCountInfo(sourceDataCountInfo));
    }

    /**
     * 修改线索数据统计
     */
    @RequiresPermissions("source:dataCountInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SourceDataCountInfo sourceDataCountInfo = sourceDataCountInfoService.selectSourceDataCountInfoById(id);
        mmap.put("sourceDataCountInfo", sourceDataCountInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存线索数据统计
     */
    @RequiresPermissions("source:dataCountInfo:edit")
    @Log(title = "线索数据统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SourceDataCountInfo sourceDataCountInfo)
    {
        return toAjax(sourceDataCountInfoService.updateSourceDataCountInfo(sourceDataCountInfo));
    }

    /**
     * 删除线索数据统计
     */
    @RequiresPermissions("source:dataCountInfo:remove")
    @Log(title = "线索数据统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sourceDataCountInfoService.deleteSourceDataCountInfoByIds(ids));
    }
}
